package com.dragon.backstage.domain.param.file;

import com.dragon.common.utils.AjaxResult;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

/**
 * 文件模块-上传文件请求参数
 *
 * @author dragon
 * @version 1.0
 * @date 2024/8/9 16:36
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(title = "文件模块-上传文件请求参数")
public class FileUploadParam {

    @Schema(title = "文件", requiredMode = Schema.RequiredMode.REQUIRED)
    private MultipartFile file;


    /**
     * 参数校验
     */
    public static AjaxResult<Void> check(FileUploadParam param) {
        if (Objects.isNull(param)) {
            return AjaxResult.failed("请求参数不能为空");
        }
        if (Objects.isNull(param.getFile())) {
            return AjaxResult.failed("上传文件不能为空");
        }

        return AjaxResult.succeed();
    }

}
